package vn.edu.ptithcm.pim.dao;

import vn.edu.ptithcm.pim.dom.Country;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

@SuppressWarnings("rawtypes")
public class CountryDao extends HibernateDaoSupport {

	public void save(Country country) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().save(country);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(Country country) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().saveOrUpdate(country);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(Country country) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().lock(country, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(Country country) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().delete(country);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Country merge(Country country) {
		try {
			return (Country) getHibernateTemplate().merge(country);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Country findById(java.lang.Long id) {
		try {
			return (Country) getHibernateTemplate().get(Country.class, id);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(Country country) {
		try {
			return getHibernateTemplate().findByExample("Country", country);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List getAll() {
		try {
			return getHibernateTemplate().loadAll(Country.class);
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
